/*
 * @lc app=leetcode.cn id=566 lang=javascript
 *
 * [566] 重塑矩阵
 */

// @lc code=start
/**
 * @param {number[][]} mat
 * @param {number} r
 * @param {number} c
 * @return {number[][]}
 */
var matrixReshape = function(mat, r, c) {
    let m = mat.length
    let n = mat[0].length
    if ( (m * n) !== (r * c) ) {
        return mat
    }
    let arr = []
    for (let index1 = 0; index1 < mat.length; index1++) {
        const e1 = mat[index1];
        for (let index2 = 0; index2 < e1.length; index2++) {
            const e2 = e1[index2];
            let index3 = arr.length - 1
            if (arr[index3] && arr[index3].length < c) {
                arr[index3].push(e2)
            } else {
                arr[index3 + 1] = [e2]
            }
        }
    }
    return arr
};
// @lc code=end


/* 

    nb，测试点成提交了结果一遍过

*/
